package com.bridgeintelligent.tag.webserver.dim.mgmt.service.dim.del;

import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DimRep;
import com.bridgeintelligent.tag.webserver.dim.mgmt.service.catalog.model.DimDelModel;
import com.bridgeintelligent.tag.webserver.dim.mgmt.service.catalog.model.DimListModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by JackCheung on 2019/9/17 2:45 PM.
 */
@Api(tags = "删除标签查看")
@RestController
@RequestMapping("api/dimDel")
public class DelDimController {

    private IDelDimService iDelDimService;

    public DelDimController(IDelDimService iDelDimService) {
        this.iDelDimService = iDelDimService;
    }

    @ApiOperation(value = "获取标签列表", notes = "基础标签管理&标签查看")
    @GetMapping("list")
    public DimRep list(@ModelAttribute DimDelModel dimDelModel) {
        checkModel(dimDelModel);
        return iDelDimService.list(dimDelModel);
    }

    private void checkModel(DimDelModel dimDelModel) {
        dimDelModel.setPageNumber(dimDelModel.getPageNumber() == null ? 1 : dimDelModel.getPageNumber());
        dimDelModel.setPageSize(dimDelModel.getPageSize() == null ? 10 : dimDelModel.getPageSize());
        if (StringUtils.isNotEmpty(dimDelModel.getDelTimeStart())) {
            dimDelModel.setDelTimeStart(dimDelModel.getDelTimeStart() + " 00:00:00");
        }
        if (StringUtils.isNotEmpty(dimDelModel.getDelTimeEnd())) {
            dimDelModel.setDelTimeEnd(dimDelModel.getDelTimeEnd() + " 23:59:59");
        }
        if (StringUtils.isNotEmpty(dimDelModel.getCreateTimeStart())) {
            dimDelModel.setCreateTimeStart(dimDelModel.getCreateTimeStart() + " 00:00:00");
        }
        if (StringUtils.isNotEmpty(dimDelModel.getCreateTimeEnd())) {
            dimDelModel.setCreateTimeEnd(dimDelModel.getCreateTimeEnd() + " 23:59:59");
        }
        if (StringUtils.isNotEmpty(dimDelModel.getUptTimeStart())) {
            dimDelModel.setUptTimeStart(dimDelModel.getUptTimeStart() + " 00:00:00");
        }
        if (StringUtils.isNotEmpty(dimDelModel.getUptTimeEnd())) {
            dimDelModel.setUptTimeEnd(dimDelModel.getUptTimeEnd() + " 23:59:59");
        }
    }
}
